package com.zxw.user.controller;


import com.zxw.common.core.base.res.BaseRes;
import com.zxw.user.api.ButtonAPI;
import com.zxw.user.domain.entity.Button;
import com.zxw.user.service.ButtonService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Xuewei.Zhang
 * @since 2022-05-04
 */
@RestController
@RequestMapping("/button")
@RequiredArgsConstructor
public class ButtonController implements ButtonAPI {

    private final ButtonService buttonService;

    @GetMapping("/menu-button")
    public BaseRes<List<Button>> getMenuButton(Button button) {
        List<Button> buttonList = buttonService.getAllByCompanyIdAndMenuId(button);
        return BaseRes.ok(buttonList);
    }

    @GetMapping("/get-button/{id}")
    public BaseRes<Button> getButton(@PathVariable("id") Long id) {
        return BaseRes.ok(buttonService.getButton(id));
    }

    @PostMapping("/add-button")
    public BaseRes<Long> addButton(@RequestBody Button button) {
        Long id = buttonService.addButton(button);
        return BaseRes.ok(id);
    }

    @PutMapping("/update-button")
    public BaseRes<Button> updateButton(@RequestBody Button button) {
        Button buttonUpdated = buttonService.updateButton(button);
        return BaseRes.ok(buttonUpdated);
    }


    @DeleteMapping("/delete-button/{ids}")
    public BaseRes deleteButton(@PathVariable("ids") String ids) {
        buttonService.delete(ids);
        return BaseRes.ok();
    }
}
